//
//  SHGHomeVisitorView.swift
//  -微博准备
//
//  Created by 孙护国 on 16/4/8.
//  Copyright © 2016年 孙护国. All rights reserved.
//

import UIKit
import SnapKit
class SHGHomeVisitorView: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        startAnimation()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func startAnimation() {
        //基本动画
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        //基本设置
        anim.repeatCount = MAXFLOAT
        //设置动画时间
        anim.duration = 15
        //
        anim.toValue = 2 * M_PI
        // 动画执行结束 或者 当前处于非活跃状态下 动画不移除图层
        anim.removedOnCompletion = false
        //添加到 圈圈的图层上
        circle.layer.addAnimation(anim, forKey: nil)
    }
    
    func setupUI(){
        addSubview(circle)
        addSubview(backImageView)
        addSubview(home)
        addSubview(tipLabel)
        addSubview(login)
        addSubview(register)
        
        //        home.snp_makeConstraints { (make) -> Void in
        //            //make 就是 circleIcon 取消了frame布局的对象
        //            make.centerX.equalTo(self.snp_centerX)
        //            make.centerY.equalTo(self.snp_centerY).offset(-80)
        //        }
        
        
        circle.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.snp_centerX)
            make.centerY.equalTo(self.snp_centerY).offset(-80)
        }
        home.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(circle.snp_center)
        }
        tipLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(circle.snp_bottom).offset(16)
            //为了能够自动换行 需要约束宽度
            make.width.equalTo(230)
            make.centerX.equalTo(circle.snp_centerX)
            
        }
        login.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(tipLabel.snp_left)
            make.top.equalTo(tipLabel.snp_bottom).offset(16)
            //约束宽度
            make.width.equalTo(100)
        }
        register.snp_makeConstraints { (make) -> Void in
            make.right.equalTo(tipLabel.snp_right)
            make.top.equalTo(tipLabel.snp_bottom).offset(16)
            make.width.equalTo(100)
        }
        backImageView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(circle)
        }
        
        //设置背景色
        let value: CGFloat = 237 / 255.0
        backgroundColor = UIColor(red: value, green: value, blue: value, alpha: 1)
    }
    private lazy var backImageView: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))
    //房子
    private lazy var home:UIImageView=UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
    //圈
    private lazy var circle:UIImageView=UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
    //提示
    private lazy var tipLabel:UILabel={
        var label:UILabel=UILabel()
        label.text="关注一些人,回到这里看看有什么惊喜"
        label.textColor=UIColor.darkGrayColor()
        label.font=UIFont.systemFontOfSize(14)
        label.sizeToFit()
        return label
    }()
    //    登陆按钮
    private lazy var login:UIButton={
        var btn:UIButton=UIButton()
        btn.setTitle("登陆", forState:.Normal)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.titleLabel?.font=UIFont.systemFontOfSize(14)
        let image = UIImage(named: "common_button_white_disable")!
        let capW = Int(image.size.width * 0.5)
        let capH = Int(image.size.height * 0.5)
        btn.titleLabel?.font=UIFont.systemFontOfSize(14)
        btn.setBackgroundImage(image.stretchableImageWithLeftCapWidth(capW, topCapHeight: capH), forState: .Normal)
        return btn
    }()
    //注册按钮
    private lazy var register:UIButton={
        var btn:UIButton=UIButton()
        btn.setTitle("注册", forState:.Normal)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        //设置背景图片
        let image = UIImage(named: "common_button_white_disable")!
        let capW = Int(image.size.width * 0.5)
        let capH = Int(image.size.height * 0.5)
        btn.titleLabel?.font=UIFont.systemFontOfSize(14)
        btn.setBackgroundImage(image.stretchableImageWithLeftCapWidth(capW, topCapHeight: capH), forState: .Normal)
        return btn
    }()
}
